﻿
namespace HSS.ComponentModel
{
	#region Using Directives
	using System;
	#endregion

	#region PasswordPropertyTextAttribute
	/// <summary>
	/// Indicates that an object's text representation is obscured by characters such as asterisks. This class cannot be inherited.
	/// </summary>
	[AttributeUsage(AttributeTargets.All)]
	public sealed class PasswordPropertyTextAttribute : Attribute
	{
		#region Fields
		private bool _password;
		/// <summary>
		/// Specifies the default value for the PasswordPropertyTextAttribute.
		/// </summary>
		/// <remarks>The default value is <see cref="No"/>.</remarks>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
		public static readonly PasswordPropertyTextAttribute Default = No;
		/// <summary>
		/// Specifies that a text property is not used as a password. This static (Shared in Visual Basic) field is read-only.
		/// </summary>
		/// <remarks>
		/// The No field is the default value for the <see cref="PasswordPropertyTextAttribute"/>.
		/// </remarks>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
		public static readonly PasswordPropertyTextAttribute No = new PasswordPropertyTextAttribute(false);
		/// <summary>
		/// Specifies that a text property is used as a password. This static (Shared in Visual Basic) field is read-only.
		/// </summary>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
		public static readonly PasswordPropertyTextAttribute Yes = new PasswordPropertyTextAttribute(true);
		#endregion

		#region Constructors
		/// <summary>
		/// Initializes a new instance of the <see cref="PasswordPropertyTextAttribute"/> class.
		/// </summary>
		public PasswordPropertyTextAttribute()
			: this(false)
		{
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="PasswordPropertyTextAttribute"/> class, optionally showing password text.
		/// </summary>
		/// <param name="password">true to indicate that the property should be shown as password text; otherwise, false. The default is false.</param>
		public PasswordPropertyTextAttribute(bool password)
		{
			this._password = password;
		}
		#endregion

		#region Properties
		/// <summary>
		/// Gets a value indicating if the property for which the <see cref="PasswordPropertyTextAttribute"/> is defined should be shown as password text.
		/// </summary>
		public bool Password
		{
			get
			{
				return this._password;
			}
		}
		#endregion

		#region Overrides
		/// <summary>
		/// Determines whether two <see cref="PasswordPropertyTextAttribute"/> instances are equal.
		/// </summary>
		/// <param name="obj">The <see cref="PasswordPropertyTextAttribute"/> to compare with the current <see cref="PasswordPropertyTextAttribute"/>.</param>
		/// <returns>true if the specified <see cref="PasswordPropertyTextAttribute"/> is equal to the current <see cref="PasswordPropertyTextAttribute"/>; otherwise, false.</returns>
		public override bool Equals(object obj)
		{
			var po = obj as PasswordPropertyTextAttribute;
			return ((null != po) && (po.Password == this._password));
		}
		/// <summary>
		/// Returns the hash code for this instance.
		/// </summary>
		/// <returns>A hash code for the current <see cref="PasswordPropertyTextAttribute"/>.</returns>
		public override int GetHashCode()
		{
			return base.GetHashCode();
		}
		#endregion

		#region Methods
		/// <summary>
		/// Returns an indication whether the value of this instance is the default value.
		/// </summary>
		/// <returns>true if this instance is the default attribute for the class; otherwise, false.</returns>
		public bool IsDefaultAttribute()
		{
			return this.Equals(Default);
		}
		#endregion
	}
	#endregion
}